package a66weding.com.jiehuntong.activity.order;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.order.adapter.EvaluationAdapter;

import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.MyOrderBean;
import a66weding.com.jiehuntong.common.MessageEvent;
import a66weding.com.jiehuntong.widgets.MyListView;

/**
 * Created by admin on 2016/8/30.
 * 评价晒单;
 */
public class EvaluationActivity extends Activity  {
    private TextView title_tv;
    private MyListView act_elt_lv;
    private EvaluationAdapter adapter;
    private View headView ;
    private MyOrderBean.DataBean orderDataBean;
    //订单编号
    private TextView header_elt_content;
    //时间
    private TextView header_elt_timecontent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evaluation);

        ((GlobalApplication) getApplication()).getActivityManager().addActivity("EvaluationActivity", this);

        EventBus.getDefault().register(this);
        Intent intent = getIntent();
        if(intent!=null) {
            Bundle extras = intent.getExtras();
            if(extras!=null) {
                orderDataBean = (MyOrderBean.DataBean) extras.get("orderDataBean");
            }
        }
        initView();
        initData();
    }

    private void initView(){
        title_tv = (TextView) findViewById(R.id.title_tv);
        title_tv.setText("评价晒单");
        act_elt_lv = (MyListView) findViewById(R.id.act_elt_lv);
        headView = View.inflate(this,R.layout.lv_header_evaluation,null);
        header_elt_content = (TextView) headView.findViewById(R.id.header_elt_content);
        header_elt_timecontent  = (TextView) headView.findViewById(R.id.header_elt_timecontent);
        act_elt_lv = (MyListView) findViewById(R.id.act_elt_lv);
    }

    private void initData(){
        header_elt_content.setText(orderDataBean.getOrdersNumber());
        header_elt_timecontent.setText(orderDataBean.getOrderSubmitDatetime());
        act_elt_lv.addHeaderView(headView);
        adapter = new EvaluationAdapter(this,orderDataBean.getMyOrderDetail());
        act_elt_lv.setAdapter(adapter);
    }

    public void back(View view){
        finish();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe
    public void onEventMainThread(MessageEvent event) {
        if (event.getWhichisPinlun()!=-1){
            adapter.setFlag(event.getWhichisPinlun());
        }
    }
}
